package com.lsk.apipassenger.service;

import com.lsk.apipassenger.remote.ServicePassengerUserClient;
import com.lsk.internalcommon.DTO.PassengerUser;
import com.lsk.internalcommon.DTO.ResponseResult;
import com.lsk.internalcommon.request.TokenRequest;
import com.lsk.internalcommon.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Autowired
    private ServicePassengerUserClient passengerUserClient;

    public ResponseResult getUserByAccessToken(String AccessToken){
        System.out.println("AccessToken:"+AccessToken);
        TokenRequest tokenRequest = JwtUtils.checkToken(AccessToken);
        String phone = tokenRequest.getPhone();

        ResponseResult<PassengerUser> userByPhone = passengerUserClient.getUserByPhone(phone);

        return ResponseResult.success(userByPhone.getData());
    }
}
